package chapter;

/**
 * 在实例初始化块中对实例变量进行初始化
 * 生成三角形的三条边
 */
public class ChuShiHua {
    private int side1;
    private int side2;
    private int side3;
    {
        while(true){
            buildSides();
            if(valid()){
                break;
            }
        }
    }
    private void buildSides(){
        side1 = (int)(Math.random()*10)+1;
        side2 = (int)(Math.random()*10)+1;
        side3 = (int)(Math.random()*10)+1;
    }
    private boolean valid(){
        return side1+side2>side3 && side1+side3>side2 &&side2+side3>side1;
    }

    public static void main(String[] args) {
        ChuShiHua c = new ChuShiHua();
        System.out.println(c.side1+","+c.side2+","+c.side3);
    }
}
